# 第一阶段：构建阶段
FROM node:18-alpine AS build
RUN apk add --no-cache curl

# 使用官方提供的最新脚本来安装 pnpm
RUN npm install -g pnpm

WORKDIR /app

# 复制 package.json 和 pnpm-lock.yaml 并安装依赖
COPY package.json pnpm-lock.yaml ./
RUN pnpm install

# 复制源代码并执行构建
COPY . ./
RUN pnpm run build

# 第二阶段：生产阶段
FROM node:18-alpine
WORKDIR /app

# 从构建阶段复制 package.json, node_modules, 和构建输出
COPY --from=build /app/package.json ./
COPY --from=build /app/node_modules ./node_modules/
COPY --from=build /app/dist ./dist/
COPY --from=build /app/config ./config/

# 暴露端口
EXPOSE 3000

# 启动应用
CMD ["node", "./dist/app.js"]